const { obd_modify_collection } = require('../config')
const { db } = require('../config')
const { command } = require('../config')
const _ = command
// 日志查询条件：新装维，旧装维，分光器名称
exports.main = async (event, context) => {
    const data = event;
    loginInfo = data.userInfo;
    filter = {};
    data.newStaffName && (filter.newStaffName = new RegExp(data.newStaffName, 'i'))
    data.oldStaffName && (filter.oldStaffName = new RegExp(data.oldStaffName, 'i'))
    data.workOrderCreator && (filter.workOrderCreator = new RegExp(data.workOrderCreator, 'i'))
    let escapedStaffName = escapeRegExp(data.obdName);
    data.obdName && (filter.obdName = new RegExp(escapedStaffName, 'i'))
    const count = await db.collection(obd_modify_collection).where(filter).count();
    page = data.page;
    pageSize = data.pageSize;
    const lists = await db.collection(obd_modify_collection).where(filter).skip(page * pageSize).limit(pageSize).get();
    return { total: count.total, data: lists.data, page, pageSize };
}
function escapeRegExp(string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}